<template>
  <div>
    <assess :editor="edit" ref="assess"/>
    <div class="sub">
      <van-button type="info" size="large" @click="toSubmit">确定</van-button>
    </div>
  </div>
</template>

<script>
import assess from '@/components/assess'
import api from '@/api'
export default {
  name: 'course-assess',
  data () {
    return {
      edit: false
    }
  },
  methods: {
    toSubmit () {
      if (this.edit) {
        this.$toast('已评价')
        return
      }
      let data = this.$refs['assess'].getAssess()
      if (!data.task) {
        this.$toast('请填写作业')
        return
      }
      let params = {
        performance: data.performance,
        task: data.task,
        remind: data.remind,
        arrangement_id: this.$route.query.id
      }
      api.teacherEditAssess({
        params,
        callback: res => {
          if (res.data.error_code === 0) {
            this.$toast({
              message: res.data.message,
              duration: 1000,
              onClose: () => {
                this.$router.go(-1)
              }
            })
          }
        }
      })
    }
  },
  components: {
    assess
  },
  created () {
    api.studentAssess({
      params: {arrangement_id: this.$route.query.id},
      callback: res => {
        if (res.data.data) {
          this.edit = true
        }
      }
    })
  }
}
</script>

<style scoped>
  .sub{
    margin-top: 20px;
    padding: 10px;
  }
</style>
